/**
 * 通过indexs位置数组找到对应的元素
 * @param cards 
 * @param indexs 
 * @returns 
 */
export const findCardByIndexs = (cards, indexs) => {
    if (!Array.isArray(indexs)) return;
    let card = cards;
    indexs.map((index, i) => {
      if (i === indexs.length - 1) card = card[index]
      else card = card[index].childrens
    })
    return card;
}

/**
 * 比较拖拽元素和放置元素的位置信息
 * @param dragIndexs 
 * @param dropIndexs 
 * @returns 
 */
export const compareIndexs = (dragIndexs: number[], dropIndexs: number[]) => {
  const info = {
    dragIndex: -1,
    dropIndex: -1,
    parentDragIndexs: [] as number[],
    parentDropIndexs: [] as number[],
    isSameParent: false,
    dragDirection: 'before',
    parentDragIsRoot: true,
    parentDropIsRoot: true,
  };
  info.parentDragIndexs = [...dragIndexs];
  info.dragIndex = info.parentDragIndexs.pop() as number;
  info.parentDropIndexs = [...dropIndexs];
  info.dropIndex = info.parentDropIndexs.pop() as number;

  if (info.parentDragIndexs.length !== 0) {
    info.parentDragIsRoot = false;
  }
  if (info.parentDropIndexs.length !== 0) {
    info.parentDropIsRoot = false;
  }

  if (info.parentDragIndexs.join('-') === info.parentDropIndexs.join('-')) {
    info.isSameParent = true;
    if (info.dropIndex > info.dragIndex) {
      info.dragDirection = 'after';
    }
  }


  return info;
}